package cn.e2win.base.controller;
import java.beans.PropertyEditorSupport;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.sql.Time;
       
public class TimeEditor extends PropertyEditorSupport {
       
    public static String FORMAT = "yyyy-MM-dd";
       
    public String getAsText() {
        Time time = (Time) getValue();
        if (time == null) {
            return "";
        }
        DateFormat formater = new SimpleDateFormat(FORMAT);
        return formater.format(time);
    }
       
    public void setAsText(String text) {
        if (text != null && text.length() > 0) {
            try {
                DateFormat formater = new SimpleDateFormat(FORMAT);
                setValue(new Time(formater.parse(text).getTime()));
            } catch (ParseException ex) {
                throw new IllegalArgumentException(ex);
            }
        }
    }
       
       
}